<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:nwisdocs="http://wales.nhs.uk/nwis/docs"
	exclude-result-prefixes="xs xsi">
	
	<xsl:template name="medications" match="nwisdocs:Medications">
		<div class="boxed-section" id="{local-name()}">
			<h2>Medications Order</h2>
      <table>
        <thead>
          <tr>
            <th colspan="7">Medications</th>
          </tr>
          <tr>
            <td/>
            <td>Medication name</td>
            <td>Stock Status</td>
            <td>Pack</td>
            <td>Order Quantity</td>
          </tr>
        </thead>
        <tbody>
          <xsl:variable name="count" select="nwisdocs:ToTakeMedications/@count" />

          <xsl:for-each select="nwisdocs:ToTakeMedications/nwisdocs:ContinuingMedication">
            <tr>
              <td><xsl:value-of select="@position"/> of <xsl:value-of select="$count"/></td>
              <td>
                <xsl:value-of select="nwisdocs:Medication/nwisdocs:DrugName/nwisdocs:DrugDescription"/> - <xsl:value-of select="nwisdocs:Medication/nwisdocs:StructuredDosage/nwisdocs:Route"/>
                <br/>DOSE - <xsl:value-of select="nwisdocs:Medication/nwisdocs:StructuredDosage/nwisdocs:Dose/nwisdocs:DoseDescription"/>
              </td>
              <td>
                <xsl:value-of select="nwisdocs:Stock/nwisdocs:Status"/>
              </td>
              <td>
                <xsl:value-of select="nwisdocs:Stock/nwisdocs:Quantity"/>
              </td>
              <td>
                <xsl:value-of select="nwisdocs:Order/nwisdocs:Quantity"/>
              </td>
            </tr>
          </xsl:for-each>
        </tbody>
      </table>
      
      <table>
        <thead>
          <tr>
            <th colspan="1">Clinical check</th>
          </tr>
        </thead>
        <tbody>
          <tr class="clinicalcheck" >
            <td>
              <span class="pharmacistchecklabel">Pharmacist check by:</span>
              <span>
                <xsl:variable name="checkedby" select="nwisdocs:ToTakeMedications/nwisdocs:PharmacyCheck/nwisdocs:CheckedBy"/>
                <xsl:value-of select="$checkedby"/>
                <xsl:choose>
                  <xsl:when test="nwisdocs:ToTakeMedications/nwisdocs:PharmacyCheck/nwisdocs:CheckedDate=''"/>
                  <xsl:otherwise>
                    on <xsl:value-of select="nwisdocs:ToTakeMedications/nwisdocs:PharmacyCheck/nwisdocs:CheckedDate"/>
                  </xsl:otherwise>
                </xsl:choose>
              </span>
            </td>
            <!--<td>
              <label>Dispensing check by:</label>
             
            </td>
            <td>
              <label>Accuracy check by:</label>
              
            </td>-->
          </tr>
        </tbody>
      </table>
		</div>
	</xsl:template>
</xsl:stylesheet>
